// pages/addProduct/previewImg/previewImg.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrls: [
      'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg',
      'http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg',
    ],
    indicatorDots: true,  //是否显示面板指示点
    autoplay: false,      //是否自动切换
    interval: 3000,       //自动切换时间间隔
    duration: 500,       //滑动动画时长
    inputShowed: false,
    inputVal: "",
    orders:"1/2", // 照片顺序
    currentIndex:0, // 当前index
    selectedPic:0, // 首图index
    bottomText:"主图", // 按钮文字
    zhutuFlag:false,

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      imgUrls: JSON.parse(decodeURIComponent(options.imgUrls)),
      picArray: JSON.parse(decodeURIComponent(options.imgUrls)),
      orders: this.data.imgUrls.length
    })
    console.log(this.data.imgUrls)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  //轮播图的切换事件  
  swiperChange: function (e) {
    this.setData({
      currentIndex: e.detail.current,
    })
    if (e.detail.current == this.data.selectedPic){
      this.setData({
        zhutuFlag:false
      })
    }else{
      this.setData({
        zhutuFlag: true
      })
    }
    wx.setNavigationBarTitle({
      title: String(e.detail.current + 1) + "/" + String(this.data.imgUrls.length)
    })
  },
  setFirst:function(e){

    this.setData({
      zhutuFlag: false,
      selectedPic: this.data.currentIndex,
      
    })
    var picArray = []
    picArray = picArray.concat(this.data.imgUrls)
    var currentPic = [picArray[this.data.currentIndex]]
    picArray.splice(this.data.currentIndex, 1);
    picArray = currentPic.concat(picArray)
    var pages = getCurrentPages()
    var prePage = pages[pages.length - 2]
    prePage.setData({ picArrays: picArray, changeImgFlag:1 })
    console.log(picArray)
  }
})